<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <jsp:include page="../include.jsp" flush="true"/>
	<script type="text/javascript">
	var grid;
	var win;
	var url;
	$(function(){
		if(user_role != 1 && user_role != 5){
			$("#query-form").hide();
		}
	})
	$(function() {
		grid = $('#user_info').datagrid();
		$('#btn-save,#btn-cancel').linkbutton();
		win = $('#user-window').window( {
			collapsible : false,//折叠
			minimizable : false,//最小化
			maximizable : false,//最大化
			draggable : true,//拖动
			resizable : false,//改变大小
			modal : true,
			closed : true
		});

	});

	function append() {
		reject();
		win.window('open');
		status = 'enable';
		$('#userform').form('clear');
		$('#plan_week').attr({onblur:"checkPlanWeek()",disabled:false});
		url ='c02!addPlan?plan_stu_id='+<%=session.getAttribute("user_id")%>;
	}
	function remove() {
		var rows = $('#table_body').datagrid('getSelected');
		if(!rows){
			show('请先选择一行数据!');
			return false;
		}
		$.messager.confirm('提示','确定要删除吗?',function(result){  
            if (result){  
                $.post('c02!removePlan?plan_id='+rows.plan_id,function(message){  
                	show(message.returnMsg);
                    $('#table_body').datagrid('reload');
                });
            } 
            reject();
        });
	}
	function update() {
		$('p').remove();
		var row = $('#table_body').datagrid('getSelected');
		if (row) {
			$('#plan_week').attr({onblur:"",disabled:'disabled'});
			win.window('open');
			$('#userform').form('clear');
			$('#userform').form('load', row);
			url = 'c02!updatePlan';
		} else {
			show("请先选择一行数据");
		}
	}
	function save() {
		$("p").remove();
		$('#userform').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				$('#table_body').datagrid('reload');
				//$('#userform').form('clear');
				win.window('close');
			}
		});
	}
	function query(){
		var params = $('#user_info').datagrid('options').queryParams; 
        var fields =$('#query-form').serializeArray();
        $.each( fields, function(i, field){
            params[field.name] = field.value;
        });   
        $('#user_info').datagrid('reload');
        $('#table_body').datagrid('reload');
	}
	function reject(){
		$('#table_body').datagrid('clearSelections');
	} 
	
	function closeWindow() {
		win.window('close');
		reject();
	}
</script>
	<script type="text/javascript">
		$(function(){
			var lastIndex;
			$('#user_info').datagrid({
				width:'auto',
				height:'auto',
				method:'post',
				nowrap: false,
				fitColumns:'true',
				fit:true,
				striped: true,
				url:'c02!queryPlanHead?user_role_id='+user_role+'&user_id='+user_id,
				idField:'STU_ID',
				columns:[[
					//{field:'ck',checkbox:true,width:2}, //显示复选框
					{field:'STU_ID',title:'学号',align:'center',width:80},
					{field:'USER_NAME',title:'姓名',align:'center',width:80},
					{field:'STU_GRADE',title:'年级',align:'center',width:40},
					{field:'STU_CLASS',title:'班级',align:'center',width:40},
					{field:'FACULTY_NAME',title:'专业',align:'center',width:90},
					{field:'MAJOR_NAME',title:'学院',align:'center',width:90},
					{field:'GROUP_NAME',title:'组名',align:'center',width:170},
					{field:'TASK_NAME',title:'课题名',align:'center',width:120},
					{field:'STU_MISSION',title:'个人任务',align:'center',width:150,
						formatter: function(value,row,index){
							if (value == null){
								return "暂无,请由组长分配!";
							} else {
								return value;
							}
						}
					}
				]],
				rownumbers:true,
				singleSelect:true,
				onDblClickRow:function(){
					var rows = grid.datagrid('getSelected');
					if(rows.STU_MISSION == null || rows.STU_MISSION == ""){
						show(rows.USER_NAME+"还没被分配任务!");
						return false;
					}
					loadbody(rows.STU_ID);
					reject();
				},
				onLoadSuccess:function(){  
               		$('#user_info').datagrid('clearSelections');
            	}
			});
		});
		
	</script>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',split:false,border:true" title="" style="height:39px">
			<form id="query-form" method="post" style="padding-left:10px;padding-top:2px;">
		  		课题名<input type="text" class="easyui-validatebox" name="taskId" style="width:90px;">&nbsp;
		  		小组名<input type="text" class="easyui-validatebox" name="groupName" style="width:90px;"></input>&nbsp;
				学号<input type="text" class="easyui-validatebox" name="stuId" style="width:90px;"></input>&nbsp;
				姓名<input type="text" class="easyui-validatebox" name="stuName" style="width:90px;"></input>&nbsp;
				所属专业<input class="easyui-combobox" name="majorId" style="width:90px;"
										data-options="
												url:'c01!queryMajor',
												mode:'remote',
												valueField:'MAJOR_ID',
												textField:'MAJOR_NAME',
												panelHeight:'auto'
									">&nbsp;
				所属学院<input class="easyui-combobox" name="facultyId" style="width:90px;"
										data-options="
												url:'c01!queryFaculty',
												mode:'remote',
												valueField:'FACULTY_ID',
												textField:'FACULTY_NAME',
												panelHeight:'auto'
									">&nbsp;&nbsp;
		        <a href="javascript:void(0)" onclick="query()" id="btn-save" icon="icon-search">查询</a>
		  	</form>
		</div>
		<div data-options="region:'center',border:false" title="个人计划表头信息">
			<table id="user_info"></table>
			<div id="user-window" title="用户窗口" style="width:450px;height:auto;">
				<div style="padding:20px 20px 40px 80px;">
					<form id="userform" method="post" >
						<table>
							<tr>
								<td>
									<input type="hidden" name="plan_stu_id" id="plan_stu_id" class="easyui-validatebox">
		        				</td>
								<td>
									
		        				</td>
							</tr>
							<tr>
								<td>计划周：</td>
								<td>
									<input name="plan_week" id="plan_week" class="easyui-numberspinner" style="width:130px;"  
		        						 required="true" data-options="min:1,max:25,editable:true" onblur="checkPlanWeek()">
		        					<script type="text/javascript">
		        						function checkPlanWeek(){
		        							$.post('c02!checkAddPlan',
		        								{stu_id:user_id, plan_week:$('#plan_week').val()},
		        								function(message){
		        									if(message.returnFlag == 'N'){
		        										$("p").remove();
														$("#check1").append("<p style='color:red'>"+message.returnMsg+"</p>");
														$('#plan_week').focus();
		        									}else{
		        										$("p").remove();
		        									}
		        								}
		        							);
		        						}
		        					</script>
		        				</td>
		        				<td><input type="hidden" name="plan_id" id="plan_id" class="easyui-validatebox" ></td>
		        				<td id="check1"></td>
							</tr>
							<tr>
								<td>预计完成：</td>
								<td><input type="text" class="easyui-validatebox" name="plan_expect" id="plan_expect" required="true" onfocus="checkPlanWeek()" style="width:130px;"></input></td>
							</tr>
							<tr>
								<td>实际完成：</td>
								<td><input type="text" class="easyui-validatebox" name="plan_done" id="plan_done" style="width:130px;"></input></td>
							</tr>
							<tr>
								<td>参与度：</td>
								<td>
									<select id="plan_attendance" class="easyui-combobox" name="plan_attendance" style="width:130px;" data-options="panelHeight:'auto'">
										<option value="非常积极">非常积极</option>
										<option value="积极">积极</option>
										<option value="一般">一般</option>
										<option value="很少">很少</option>
										<option value="完全没有">完全没有</option>
									</select>
								</td>
							</tr>
							<tr>
								<td>贡献度：</td>
								<td>
									<select id="plan_contribution" class="easyui-combobox" name="plan_contribution" style="width:130px;" data-options="panelHeight:'auto'">
										<option value="非常高">非常高</option>
										<option value="高">高</option>
										<option value="一般">一般</option>
										<option value="很少">很少</option>
										<option value="完全没有">完全没有</option>
									</select>
								</td>
							</tr>
							<tr>
								<td>备注：</td>
								<td>
									<textarea name="plan_note" id="plan_note" class="easyui-validatebox" style="width:130px;"></textarea>
		        				</td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;padding:5px;">
					<a href="javascript:void(0)" onclick="save()" id="btn-save" icon="icon-save">确认</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeWindow()" id="btn-cancel" icon="icon-cancel">取消</a>
				</div>
			</div>
		</div>
		
		<div data-options="region:'south',split:true,border:false" title="个人计划列表" style="height:250px">
			<table id="table_body"></table>
		</div>
	</div>
	<script type="text/javascript" src="./jquery-easyui-1.3.2/easyloader.js"></script>
	<script type="text/javascript">
		function loadbody(stu_id){
			using('datagrid', function(){
				$('#table_body').datagrid({
					width:'auto',
					fit:true,
					height:'auto',
					method:'post',
					toolbar:toolbar,
					nowrap: false,
					fitColumns:'true',
					striped: true,
					url:'c02!queryPlanBody?stu_id='+stu_id,
					idField:'plan_id',
					columns:[[
						{field:'ck',checkbox:true,width:2}, //显示复选框
						{field:'plan_id',title:'个人计划主键',align:'center',width:120,hidden:true},
						{field:'plan_stu_id',title:'学号',align:'center',width:120},
						{field:'plan_week',title:'周次',align:'center',width:40},
						{field:'plan_expect',title:'预计完成',align:'center',width:120},
						{field:'plan_done',title:'实际完成',align:'center',width:120},
						{field:'plan_cre_time',title:'最后更新',align:'center',width:120},
						{field:'plan_attendance',title:'参与度',align:'center',width:80},
						{field:'plan_contribution',title:'贡献度',align:'center',width:80},
						{field:'plan_note',title:'备注',align:'center',width:120}
					]],
					rownumbers:true,
					singleSelect:true
				});
			});
		}
		if(user_role_id == 1 || user_role_id == 5){
			var toolbar = [];
		}else{
			var toolbar = [{
				text:'增加',
				iconCls:'icon-add',
				handler:function(){append()}
			},{
				text:'修改',
				iconCls:'icon-edit',
				handler:function(){update()}
			},{
				text:'删除',
				iconCls:'icon-cut',
				handler:function(){remove()}
			},{
				text:'返回',
				iconCls:'icon-undo',
				handler:function(){reject()}
			}];
		}
	</script>
  </body>
</html>
